package com.zjk.toolkit.dynamic.thread.pool.sdk.domain.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.ThreadPoolExecutor;

@Data
@NoArgsConstructor
public class ThreadPoolEntity {
    /**
     * 应用名称
     */
    private String appName;

    /**
     * 线程池名称
     */
    private String threadPoolName;

    /**
     * 核心线程数
     */
    private int corePoolSize;

    /**
     * 最大线程数
     */
    private int maximumPoolSize;

    /**
     * 当前活跃线程数
     */
    private int activeCount;

    /**
     * 当前池中线程数
     */
    private int poolSize;

    /**
     * 队列类型
     */
    private String queueType;

    /**
     * 当前队列任务数
     */
    private int queueSize;

    /**
     * 队列剩余任务数
     */
    private int remainingCapacity;

    public ThreadPoolEntity(String appName, String threadPoolName) {
        this.appName = appName;
        this.threadPoolName = threadPoolName;
    }

    public ThreadPoolEntity(String appName, String threadPoolName, ThreadPoolExecutor executor) {
        this.appName = appName;
        this.threadPoolName = threadPoolName;
        this.corePoolSize = executor.getCorePoolSize();
        this.maximumPoolSize = executor.getMaximumPoolSize();
        this.activeCount = executor.getActiveCount();
        this.poolSize = executor.getPoolSize();
        this.queueType = executor.getQueue().getClass().getSimpleName();
        this.queueSize = executor.getQueue().size();
        this.remainingCapacity = executor.getQueue().remainingCapacity();
    }

}
